<?php
/*
 * Glorious Framework
 *
 * Benchmark class
 *
 * (c) 2007-2010 Konspire Design
 *
 * $Id: benchmark.php,v 204646426a58 2010/04/29 12:06:51 and $
 * $Author: and $
 * $Date: 2010/04/29 12:06:51 $
 */

class Benchmark extends Singleton
{
    protected $marker = array();

    static public function &instance() {
        return parent::instance(__CLASS__);
    }

    protected function __construct() {}

    public function mark($name)
    {
        $this->marker[$name] = microtime();
    }

    public function elapsed_time($point1 = '', $point2 = '', $decimals = 4)
    {
        if($point1 == '')
            return '{elapsed_time}';

        if(!isset($this->marker[$point1]))
            return '';

        if(!isset($this->marker[$point2]))
            $this->marker[$point2] = microtime();

        list($sm, $ss) = explode(' ', $this->marker[$point1]);
        list($em, $es) = explode(' ', $this->marker[$point2]);

        return number_format(($em + $es) - ($sm + $ss), $decimals);
    }

    public function memory_usage()
    {
        return '{memory_usage}';
    }
}

/* End of file benchmark.php */
/* Location: ./system/libraries/benchmark.php */